package com.burgeon.backend.Rest.User.vipType;
/**
 * 获取门店导购
 */


import com.burgeon.backend.Rest.base.RESTBase;
import com.burgeon.backend.SHOPBACKEND.entity.Employee;
import org.json.JSONArray;
import org.springframework.util.MultiValueMap;

import java.util.ArrayList;
import java.util.HashMap;

public class FindEmpNameByNO extends RESTBase {

    private String ip;
    private String account;
    private String password;

    public FindEmpNameByNO(String ip, String account, String password) {
        this.ip = ip;
        this.account = account;
        this.password = password;
    }

    /**
     * 发送并接收字符创
     */

    public String getData(String empNO) throws Exception {
        String url = "http://" + ip + "/servlets/binserv/Rest";

        String str = RESULT(Data(empNO), url);
//        System.err.println(str);

        String count = new JSONArray(str).getJSONObject(0).getString("count");
        String empName=null;
        if(!"0".equals(count)) {
            JSONArray jsonArray = new JSONArray(str).getJSONObject(0).getJSONArray("rows");
            empName = jsonArray.getJSONArray(0).getString(0);
        }

        return empName;
    }

    private MultiValueMap Data(String empNO) {
        HashMap params = new HashMap();
        ArrayList columns = new ArrayList();//查询字段
//        columns.add("ID");

        columns.add("NAME");//\
//        columns.add("SEX");//\
//        columns.add("PHONE");//\
//        columns.add("NO");


        params.put("columns", columns);
        params.put("table", "C_V_EMPLOYEE");//表名

        params.put("count", "true");

        HashMap orderby = new HashMap();

        orderby.put("column", "ID");
        orderby.put("asc", "false");
        ArrayList list = new ArrayList();
        list.add(orderby);

        params.put("orderby", list);

        HashMap paramss = new HashMap();
        String ac =  "'="+empNO+"'";//编号

        paramss.put("column", "NO");
        paramss.put("condition", ac);

        params.put("params", paramss);
        return DATA("Query", params, account, password);
    }


    public static void main(String[] args) {
        FindEmpNameByNO g = new FindEmpNameByNO("59.110.28.94:90", "nea@burgeon.com.cn", "burgeon55321");
        try {
            System.err.println(g.getData("290"));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
